home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / tvdmx.exe / SAMPLES.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-16  |  24.7 KB  |  820 lines

  1.  
  2. {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
  3. {                            }
  4. {    SAMPLES   --Multi-window sample demo program    }
  5. {    tvDMX     --data editing project (ver 1.5)    }
  6. {                            }
  7. {    Copyright (c) 1992  Randolph Beck        }
  8. {                P.O. Box  56-0487        }
  9. {                Orlando, FL 32856        }
  10. {                CIS:  72361,753        }
  11. {                            }
  12. {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
  13.  
  14. Program SAMPLES;
  15.  
  16. { This program was written to demonstrate various data structures.  You can
  17.   examine the field templates and copy some portions into WORKSHOP.PAS for
  18.   your own experiments.
  19.  
  20.   The design of some of these record structures may seem pointless since
  21.   they are intended only to demonstrate the interface mechanism.
  22.  
  23.   The "Account" window is the simplest example here.  It's somewhat bland,
  24.   but most programmers will only require simple data structures like this.
  25.  
  26.   The "Payroll" window is a larger data window.  It demonstrates the 'Z'
  27.   template code, which forces the display of leading zeroes in that field.
  28.   Its last three fields are marked as READ-ONLY (with the ^R code).  These
  29.   are entered automatically by the virtual methods in object TDmxPayroll,
  30.   which overrides TDmxEditor.
  31.  
  32.   The "Busy" window uses a more complex template string.  Note the heavy use
  33.   of control codes, and that the last field in the main window is Read-Only.
  34.   One of the integer fields is marked as a "skip" field (that means that the
  35.   cursor will not land on it).
  36.  
  37.   The DateTime type is used here, with fldDATETIME, fldDATE, and fldTIME
  38.   constants --as defined in the DMXGIZMA unit.  Its Year, Month and Day are
  39.   swapped by codes in the fldDATETIME and fldDATE string to place it in its
  40.   more familiar Month-Day-Year order.
  41.  
  42.  
  43.   Two other views are available from the menu:  "Hex" is a tvDMX-driven
  44.   hex-byte editor using the same data as Busy window;  and "Dialog" is a
  45.   dialog box that uses tvDMX descendants for individual field input, using
  46.   the data in the current window at the current record.  A dialog window
  47.   may also be actuated by double-clicking a record with a mouse.
  48.  
  49.   The data in most windows can be reported to file SAMPLES.OUT, using the
  50.   objects in unit tvDMXREP.PAS.
  51.  
  52.   (See file TVDMXHEX.PAS for the code used in the hexadecimal byte editor.)
  53.  }
  54.  
  55. {$V-,X+ }
  56.  
  57. uses
  58.     Dos, { required to define DateTime type }
  59.     Objects, Drivers, Views, Menus, Dialogs, App, MsgBox,
  60.     RSet, DmxGizma, tvDMX, StdDMX, tvDmxHex, tvDmxRep, tvGizma;
  61.  
  62. const
  63.     ReportName    =  'SAMPLES.OUT';
  64.  
  65.     cmHasDialog   =  103;
  66.  
  67.     cmAccounts    =  111;
  68.     cmPayroll     =  112;
  69.     cmBusyWin     =  113;
  70.     cmHexWin      =  114;
  71.     cmDialog      =  115;
  72.     cmRecDialog   =  116;
  73.     cmReport      =  117;
  74.  
  75.     cmNoCmd       = 1000;
  76.  
  77.     hcMenus       = 1000;
  78.     hcDeskTop     = 1100;
  79.     hcAccounts    = 1100;
  80.     hcPayroll     = 1200;
  81.     hcBusyWin     = 1300;
  82.     hcHexWin      = 1400;
  83.     hcDialogs     = 4000;
  84.  
  85.  
  86.       { Data presentation template for the "Accounts" window.
  87.         The data structure is declared as "TAccount" in the TYPE section.
  88.        }
  89.  
  90.     AccountLabel : string =
  91.     ' Transaction          Debit        Credit      [?] ';
  92.  
  93.     AccountInfo  : string =
  94.     ' SSSSSSSSSSSSSSSS| rrr,rrr.rr  | rrr,rrr.rr  | [x] ';
  95.  
  96.  
  97.  
  98.       { Data presentation template for the "Payroll" window.
  99.     The data structure is declared as "TPayroll" in the TYPE section.
  100.     The last three fields are marked READ-ONLY, and are automatically
  101.     entered by the virtual methods in object TDmxPayroll.
  102.        }
  103.  
  104.     _PayrollLabel = ' Employee                ID     Earnings       FICA        FITW        SITW   ';
  105.     _PayrollInfo  = ' ssssssssssssssssssssss| ZZW ║ $rr,rrr.rr | $r,rrr.rr '^R'| $r,rrr.rr '^R'| $r,rrr.rr '^R;
  106.  
  107.     PayrollLabel  :  string [length (_PayrollLabel)]  =  _PayrollLabel;
  108.     PayrollInfo   :  string [length (_PayrollInfo)]   =  _PayrollInfo;
  109.  
  110.  
  111.  
  112.       { This next screen will be a bit busy, but I wanted to implement many
  113.     of the special options.  I thought it might be easier to decipher
  114.     all this by separating the field-strings into one field per line.
  115.     Each line (except the first) begins with a field delimiter.
  116.     The data structure is declared as "TBusyData" in the TYPE section.
  117.        }
  118.  
  119.     _BusyLabel    =
  120.     ' Name                    SSN             Balance     Start Date   Time   <A>  [B]   Pointer       Value     RO ';
  121.  
  122.     _BusyInfo     =   'B' + ^H        { hidden byte field }
  123.             + #0' ssssssssssssssssssssss'  { Name field }
  124.             + '| ###-##-#### '    { string of numerics only }
  125.             + '|r,rrr,rrr    '    { positive or negative }
  126.  
  127.            { DateTime type: }
  128.             + '|' + fldDATE    { untyped constants }
  129.             + #0  + fldTIME    { defined in DMXGIZMA.PAS }
  130.  
  131.             + '|iii ' + ^Z^R^S    { showzeroes/readonly/skip }
  132.             + '\iii '        { normal integer }
  133.             + '| HHHH:HHHH '    { hex longint value }
  134.             + '|RRR,RRR.RRR '    { positive values only }
  135.             + '| hh ' + ^Z^R;    { showzeroes/readonly field }
  136.  
  137.  
  138.     BusyInfo      :  string [length (_BusyInfo)]  =  _BusyInfo;
  139.     BusyLabel     :  string [length (_BusyLabel)] =  _BusyLabel;
  140.  
  141.  
  142.     MaxRecordNum  =   29;
  143.  
  144.  
  145.  
  146. type
  147.     PAccount      = ^TAccount;
  148.     PPayroll      = ^TPayroll;
  149.     PBusyData     = ^TBusyData;
  150.  
  151.  
  152.     TAccount      =  RECORD
  153.     Account    :  string [16];
  154.     Debit    :  real;
  155.     Credit    :  real;
  156.     Status    :  boolean;
  157.     end;
  158.  
  159.  
  160.     TPayroll      =  RECORD
  161.     Employee :  string [22];
  162.     ID       :  word;
  163.     Earnings :  real;
  164.     FICA     :  real;  { READ-ONLY }
  165.     FITW     :  real;  { READ-ONLY }
  166.     SITW     :  real;  { READ-ONLY }
  167.     end;
  168.  
  169.  
  170.     TBusyData     =  RECORD
  171.     Marker        :  byte;    { HIDDEN field }
  172.     Name        :  string [22];
  173.     SSN        :  string [9];
  174.     realfield1    :  real;
  175.     DT        :  datetime;
  176.     intfield0    :  integer;    { READ-ONLY }
  177.     intfield1    :  integer;
  178.     ptrfield    :  pointer;
  179.     realfield2    :  real;
  180.     hextwo        :  byte;    { READ-ONLY }
  181.     end;
  182.  
  183.  
  184.     PDmxEditTbl     = ^TDmxEditTbl;
  185.     PDmxEditTblWin  = ^TDmxEditTblWin;
  186.  
  187.  
  188.     TDmxEditTbl     =  OBJECT (TDmxEditor)
  189.       procedure HandleEvent (var Event : TEvent);  VIRTUAL;
  190.     end;
  191.  
  192.  
  193.     TDmxEditTblWin  =  OBJECT (TDmxWindow)
  194.       procedure InitDMX (ATemplate : string;  var AData;
  195.                          ALabels, ARecInd : PDmxLink;
  196.                          BSize  : longint);  VIRTUAL;
  197.     end;
  198.  
  199.  
  200.     PDmxPayroll    = ^TDmxPayroll;
  201.     PDmxPayrollWin = ^TDmxPayrollWin;
  202.  
  203.  
  204.     TDmxPayroll    =  OBJECT (TDmxEditTbl)
  205.       procedure EvaluateField;  VIRTUAL;
  206.       procedure ZeroizeField (Whole :boolean; Field :pDMXfieldrec);  VIRTUAL;
  207.       procedure RecalcRecord;
  208.     end;
  209.  
  210.  
  211.     TDmxPayrollWin =  OBJECT (TDmxWindow)
  212.       procedure InitDMX (ATemplate : string;  var AData;
  213.                          ALabels, ARecInd : PDmxLink;
  214.                          BSize  : longint);  VIRTUAL;
  215.     end;
  216.  
  217.  
  218.     PMyStatusLine  = ^TMyStatusLine;
  219.     TMyStatusLine  =  OBJECT (TStatusLine)
  220.       function  Hint (AHelpCtx : word) : string;  VIRTUAL;
  221.     end;
  222.  
  223.  
  224.     TAppN          =  OBJECT (TAppA)
  225.     end;
  226.  
  227.  
  228.     TMyApp         =  OBJECT (TAppN)
  229.       constructor Init;
  230.       procedure Idle;  VIRTUAL;
  231.       procedure HandleEvent (var Event : TEvent);  VIRTUAL;
  232.       procedure InitMenuBar;     VIRTUAL;
  233.       procedure InitStatusLine;  VIRTUAL;
  234.       procedure AccountWindow;
  235.       procedure PayrollWindow;
  236.       procedure BusyWindow;
  237.       procedure HexWindow;
  238.       procedure AccountDialog (P : PDmxEditTbl);
  239.       procedure PayrollDialog (P : PDmxPayroll);
  240.       procedure BusyDialog (P : PDmxEditTbl);
  241.     end;
  242.  
  243.  
  244. var
  245.     Accounts   :  array [0..49] of TAccount;
  246.     Payroll    :  array [0..49] of TPayroll;
  247.     BusyData   :  array [0..MaxRecordNum] of TBusyData;
  248.  
  249.  
  250.   procedure InitializeData;  forward;  { for the sample data }
  251.  
  252.  
  253.   { ══ TMyStatusLine ═════════════════════════════════════════════════════ }
  254.  
  255.  
  256. function  TMyStatusLine.Hint (AHelpCtx : word) : string;
  257. begin
  258.   Case AHelpCtx of
  259.     hcDragging:  Hint := #24#25#26#27' Move  Shift-'#24#25#26#27' Resize  '#17#196#217' Done  Esc Cancel';
  260.    else          Hint := '';
  261.     end;
  262. end;
  263.  
  264.  
  265.   { ══ TDmxEditTbl ═══════════════════════════════════════════════════════ }
  266.  
  267.  
  268. procedure TDmxEditTbl.HandleEvent (var Event : TEvent);
  269. begin
  270.   With Event do
  271.     If ((What = evMouseDown) and Double and DoubleValid) or
  272.        ((What = evCommand) and (Command = cmDialog))
  273.      then
  274.       begin
  275.       Message (Application, evCommand, cmRecDialog, @Self);
  276.       ClearEvent (Event);
  277.       end
  278.      else
  279.       If (What = evCommand) and (Command = cmHasDialog) then
  280.     ClearEvent (Event)
  281.        else
  282.     TDmxEditor.HandleEvent (Event);
  283. end;
  284.  
  285.  
  286.   { ══ TDmxEditTblWin ════════════════════════════════════════════════════ }
  287.  
  288.  
  289. procedure TDmxEditTblWin.InitDMX (ATemplate : string;  var AData;
  290.                   ALabels, ARecInd : PDmxLink;
  291.                   BSize  : longint);
  292. { To override TDmxEditor (as does object TDmxEditTbl above), you need
  293.   to override a TDmxWindow object to insert the new object.
  294.  }
  295. var  R  : TRect;
  296. begin
  297.   GetExtent (R);
  298.   R.Grow (-1,-1);
  299.   If ALabels <> nil then Inc (R.A.Y, 2);
  300.  
  301.   Insert (New (PDmxEditTbl, Init (ATemplate, AData, BSize, R,
  302.                 ALabels, ARecInd,
  303.                 StandardScrollBar (sbHorizontal+ sbHandleKeyboard),
  304.                 StandardScrollBar (sbVertical  + sbHandleKeyboard))));
  305.  
  306. end;
  307.  
  308.  
  309.   { ══ TDmxPayroll ═══════════════════════════════════════════════════════ }
  310.  
  311.  
  312. procedure TDmxPayroll.EvaluateField;
  313. { virtual method called after a field is edited }
  314. begin
  315.   TDmxEditor.EvaluateField;
  316.   If (CurrentField^.fieldnum = 3) and FieldAltered then RecalcRecord;
  317. end;
  318.  
  319.  
  320. procedure TDmxPayroll.ZeroizeField (Whole : boolean; Field : pDMXfieldrec);
  321. { virtual method called to clear a field }
  322. begin
  323.   TDmxEditor.ZeroizeField (Whole, Field);
  324.   If (Field^.fieldnum = 3) then RecalcRecord;
  325. end;
  326.  
  327.  
  328. procedure TDmxPayroll.RecalcRecord;
  329. { new method to follow up on changes }
  330. begin
  331.   With Payroll [CurrentRecord] do
  332.     begin
  333.     FICA  := Earnings * 0.075;
  334.     FITW  := Earnings * 0.28;
  335.     SITW  := Earnings * 0.05;
  336.     end;
  337.   RedrawRecord := TRUE;  { forces entire record to be redrawn }
  338. end;
  339.  
  340.  
  341.   { ══ TDmxPayrollWin ════════════════════════════════════════════════════ }
  342.  
  343.  
  344. procedure TDmxPayrollWin.InitDMX (ATemplate : string;  var AData;
  345.                                   ALabels, ARecInd : PDmxLink;
  346.                                   BSize  : longint);
  347. { To override TDmxEditor (as does object TDmxPayroll above), you need
  348.   to override a TDmxWindow object to insert the new object.
  349.  }
  350. var  R  : TRect;
  351. begin
  352.   GetExtent (R);
  353.   R.Grow (-1,-1);
  354.   If ALabels <> nil then Inc (R.A.Y, 2);
  355.  
  356.   Insert (New (PDmxPayroll, Init (ATemplate, AData, BSize, R,
  357.                   ALabels, ARecInd,
  358.                   StandardScrollBar (sbHorizontal+ sbHandleKeyboard),
  359.                   StandardScrollBar (sbVertical  + sbHandleKeyboard))));
  360.  
  361. end;
  362.  
  363.  
  364.   { ══ TMyApp ════════════════════════════════════════════════════════════ }
  365.  
  366.  
  367. constructor TMyApp.Init;
  368. begin
  369.   TAppN.Init;
  370.   MenuBar^.HelpCtx := hcMenus;
  371.   DeskTop^.HelpCtx := hcDeskTop;
  372.   InitializeData;  { initialize the sample data }
  373.  
  374.   { Open the first 4 selections }
  375.   AccountWindow;
  376.   PayrollWindow;
  377.   BusyWindow;
  378.   HexWindow;
  379.  
  380.   DeskTop^.SelectNext (FALSE);  { change back to account window }
  381.  
  382.   MessageBox (^C'Sample Data Editors'^M^M^C'tvDMX (c) 1992  Randolph Beck',
  383.         nil, mfInformation + mfOKButton);
  384.  
  385. end;
  386.  
  387.  
  388. procedure TMyApp.Idle;
  389. begin
  390.   TAppN.Idle;
  391.   If (Message (DeskTop, evCommand, cmHasDialog, @Self) <> nil) then
  392.     EnableCommands ([cmDialog,cmReport])
  393.    else
  394.     begin
  395.     DisableCommands ([cmDialog]);
  396.     If (Message (DeskTop, evCommand, cmDMX_RollCall, @Self) <> nil) then
  397.       EnableCommands ([cmReport])
  398.      else
  399.       DisableCommands ([cmReport]);
  400.     end;
  401. end;
  402.  
  403.  
  404. procedure TMyApp.HandleEvent (var Event : TEvent);
  405.  
  406.     procedure DoRecDialog;
  407.     var  P : PDmxEditTbl;
  408.     begin
  409.       P := Event.InfoPtr;
  410.       If (P <> nil) then
  411.     begin
  412.     If (P^.WorkingData = @Accounts) then AccountDialog (P)
  413.     else
  414.     If (P^.WorkingData = @Payroll)  then PayrollDialog (PDmxPayroll (P))
  415.     else
  416.     If (P^.WorkingData = @BusyData) then BusyDialog (P);
  417.     end;
  418.     end;
  419.  
  420.     procedure DoReport;
  421.     var  P      : PDmxScroller;
  422.          Report : PDmxReportFile;
  423.     begin
  424.       P := Message (DeskTop, evCommand, cmDMX_RollCall, @Self);
  425.       If (P <> nil) then
  426.     begin
  427.     { use different record numbering format for hex listings }
  428.     If (Message (DeskTop, evCommand, cmHasDialog, @Self) <> nil) then
  429.       Report := New (PDmxReportFile, Init (P, '|', TRUE, 50,78, ReportName))
  430.      else
  431.       Report := New (PDmxReportHexFile, Init (P, ' ', TRUE, 48,78, ReportName));
  432.     DmxReportBox ('Working',
  433.               'Processing report...'^M^M^C'File '+ ReportName, Report);
  434.         end;
  435.     end;
  436.  
  437. begin
  438.   TAppN.HandleEvent (Event);
  439.   If Event.What = evCommand then
  440.     begin
  441.     Case Event.Command of
  442.       cmAccounts:    AccountWindow;
  443.       cmPayroll:    PayrollWindow;
  444.       cmBusyWin:    BusyWindow;
  445.       cmHexWin:        HexWindow;
  446.       cmRecDialog:    DoRecDialog;
  447.       cmReport:        DoReport;
  448.      else
  449.       Exit;
  450.       end;
  451.     ClearEvent (Event);
  452.     end;
  453. end;
  454.  
  455.  
  456. procedure TMyApp.InitMenuBar;
  457. var  R: TRect;
  458. begin
  459.   GetExtent (R);
  460.   R.B.Y := R.A.Y + 1;
  461.   MenuBar := New (PMenuBar, Init (R, NewMenu (
  462.     NewSubMenu ('~S~amples', hcMenus, NewMenu (
  463.       NewItem ('~A~ccounts', '',    kbNoKey, cmAccounts,hcMenus,
  464.       NewItem ('~P~ayroll',  '',    kbNoKey, cmPayroll, hcMenus,
  465.       NewItem ('~B~usy',     'F4',  kbF4,    cmBusyWin, hcMenus,
  466.       NewItem ('~H~ex',      '',    kbNoKey, cmHexWin,  hcMenus,
  467.       NewLine (
  468.       NewItem ('~D~ialog',   'F2',  kbF2,    cmDialog,  hcMenus,
  469.       NewItem ('~R~eport',   'F9',  kbF9,    cmReport,  hcMenus,
  470.       NewLine (
  471.       NewItem ('e~X~it',   'Alt-X', kbAltX,  cmQuit,    hcMenus,
  472.       nil)))))))))),
  473.     NewSubMenu ('~W~indow', hcMenus, NewMenu (
  474.       NewItem ('~S~ize/Move', 'Ctrl-F5', kbCtrlF5, cmResize, hcMenus,
  475.       NewItem ('~Z~oom',      'F5',  kbF5,    cmZoom,    hcMenus,
  476.       NewItem ('~T~ile',      '',    kbNoKey, cmTile,    hcMenus,
  477.       NewItem ('C~a~scade',   '',    kbNoKey, cmCascade, hcMenus,
  478.       NewItem ('~N~ext',      'F6',  kbF6,    cmNext,    hcMenus,
  479.       NewItem ('~P~revious',  'Shift-F6', kbShiftF6, cmPrev, hcMenus,
  480.       NewItem ('~C~lose', 'Alt-F3',  kbAltF3, cmClose,   hcMenus,
  481.       NewLine (
  482.       NewItem ('~U~ser screen', 'Alt-F5',  kbAltF5, cmUserScreen, hcMenus,
  483.       nil)))))))))),
  484.     NewSubMenu ('~O~ptions', hcMenus, NewMenu (
  485.       NewSoundItem (hcMenus,
  486.       NewVideoItem (hcMenus,
  487.       nil))),
  488.     nil)
  489.   )))));
  490. end;
  491.  
  492.  
  493. procedure TMyApp.InitStatusLine;
  494. var  R: TRect;
  495. begin
  496.   GetExtent (R);
  497.   R.A.Y := R.B.Y - 1;
  498.   StatusLine := New (PMyStatusLine, Init (R,
  499.     NewStatusDef (hcNoContext, hcDeskTop - 1,
  500.       NewStatusKey ('tv~DMX~', kbNoKey, cmNoCmd,
  501.       nil),
  502.     NewStatusDef (hcDeskTop, hcDialogs - 1,
  503.       NewStatusKey ('~F10~ Menu',     kbF10,   cmMenu,
  504.       NewStatusKey ('~F2~ Dialog',    kbF2,    cmDialog,
  505.       NewStatusKey ('~F5~ Zoom',      kbF5,    cmZoom,
  506.       NewStatusKey ('~F6~ Next',      kbF6,    cmNext,
  507.       nil)))),
  508.     NewStatusDef (hcDialogs, $FFFF,
  509.       NewStatusKey ('~Esc~ Cancel',   kbEsc,   cmCancel,
  510.       nil),
  511.     nil)))
  512.   ));
  513. end;
  514.  
  515.  
  516. procedure TMyApp.AccountWindow;
  517. var  R  : TRect;
  518.      W  : PDmxWindow;
  519. begin
  520.   R.Assign (0, 0, length (AccountLabel) + 2, 9);
  521.   R.Move (Random (26), Random (14));
  522.   W := New (PDmxEditTblWin, Init (R,    { window rectangle }
  523.         'Accounts',        { window title }
  524.         NextWindowNumber,    { window number }
  525.         AccountInfo,        { template string }
  526.         Accounts,        { data records }
  527.         sizeof (Accounts),    { data size }
  528.         AccountLabel,        { heading label }
  529.         7));            { indicator width }
  530.   W^.HelpCtx := hcAccounts;
  531.   DeskTop^.Insert (ValidView (W));
  532. end;
  533.  
  534.  
  535. procedure TMyApp.PayrollWindow;
  536. var  R  : TRect;
  537.      W  : PDmxWindow;
  538. begin
  539.   R.Assign (0, 0, 58, 11);
  540.   R.Move (Random (22), Random (12));
  541.   W := New (PDmxPayrollWin, Init (R,    { window rectangle }
  542.         'Payroll',        { window title }
  543.         NextWindowNumber,    { window number }
  544.         PayrollInfo,        { template string }
  545.         Payroll,        { data records }
  546.         sizeof (Payroll),    { data size }
  547.         PayrollLabel,        { heading label }
  548.         7));            { indicator width }
  549.   W^.HelpCtx := hcPayroll;
  550.   DeskTop^.Insert (ValidView (W));
  551. end;
  552.  
  553.  
  554. procedure TMyApp.BusyWindow;
  555. var  R  : TRect;
  556.      W  : PDmxWindow;
  557. begin
  558.   R.Assign (0, 0, 41, 15);
  559.   R.Move (Random (39), Random (8));
  560.   W := New (PDmxEditTblWin, Init (R,    { window rectangle }
  561.         'Busy Window',        { window title }
  562.         NextWindowNumber,    { window number }
  563.         BusyInfo,        { template string }
  564.         BusyData,        { data records }
  565.         sizeof (BusyData),    { data size }
  566.         BusyLabel,        { heading label }
  567.         10));            { indicator width }
  568.   W^.HelpCtx := hcBusyWin;
  569.   DeskTop^.Insert (ValidView (W));
  570. end;
  571.  
  572.  
  573. procedure TMyApp.HexWindow;
  574. { uses objects in file tvDMXHEX.PAS }
  575. var  R  : TRect;
  576.      W  : PDmxWindow;
  577. begin
  578.   R.Assign (0, 0, length (HexLabels) + 2, 10);
  579.   W := New (PDmxHexWin, Init (R, 'Hex Window', NextWindowNumber,
  580.                   BusyData, sizeof (BusyData)));
  581.   W^.HelpCtx := hcHexWin;
  582.   W^.Options := W^.Options or ofCentered;
  583.   DeskTop^.Insert (ValidView (W));
  584. end;
  585.  
  586.  
  587. procedure TMyApp.AccountDialog (P : PDmxEditTbl);
  588. var  R       : TRect;
  589.      Dialog  : PCursorDlg;
  590.      B       : PButton;
  591.      A       : string;
  592.      Control : word;
  593. begin
  594.   Str (succ (P^.CurrentRecord), A);
  595.   DeskTop^.GetExtent (R);
  596.   Dialog := New (PCursorDlg, Init (R, 'Account Record #' + A));
  597.   If (Dialog <> nil) then
  598.     begin
  599.     With Dialog^ do
  600.       begin
  601.       HelpCtx  := hcDialogs;
  602.       InsertField (Dialog, 5,2, TRUE,  ' ~T~ransaction', ' SSSSSSSSSSSSSSSS');
  603.       InsertField (Dialog, 2,5, TRUE,  '    ~D~ebit        Credit', ' rrr,rrr.rr  \ rrr,rrr.rr  ');
  604.       InsertField (Dialog, 6,8, FALSE, '~S~tatus: ', '~[Cleared]~'^X);
  605.       R.Assign (0, 10, 10, 12);
  606.       B := New (PButton, Init (R, 'O~K~', cmOK, bfDefault));
  607.       B^.Options := B^.Options or ofCenterX;
  608.       Insert (B);
  609.       SelectNext (FALSE);
  610.       SetData (Accounts [P^.CurrentRecord]);
  611.       end;
  612.     TrimDialog (Dialog);
  613.     Control := DeskTop^.ExecView (Dialog);
  614.     If (Control = cmOK) then
  615.       begin
  616.       { return record to table }
  617.       Dialog^.GetData (Accounts [P^.CurrentRecord]);
  618.       { redraw all windows that use Accounts }
  619.       Message (DeskTop, evBroadcast, cmDMX_DrawData, @Accounts);
  620.       end;
  621.     Dispose (Dialog, Done);
  622.     end;
  623. end;
  624.  
  625.  
  626. procedure TMyApp.PayrollDialog (P : PDmxPayroll);
  627. var  R       : TRect;
  628.      Dialog  : PCursorDlg;
  629.      B       : PButton;
  630.      A       : string;
  631.      Control : word;
  632. begin
  633.   Str (succ (P^.CurrentRecord), A);
  634.   DeskTop^.GetExtent (R);
  635.   Dialog := New (PCursorDlg, Init (R, 'Employee Record #' + A));
  636.   If (Dialog <> nil) then
  637.     begin
  638.     With Dialog^ do
  639.       begin
  640.       HelpCtx  := hcDialogs;
  641.       InsertField (Dialog, 2,2, FALSE, '~N~ame: ', ' ssssssssssssssssssssss');
  642.       InsertField (Dialog, 2,4, FALSE, '~I~D Number: ', ' ZZW ');
  643.       InsertField (Dialog, 2,6, FALSE, '~E~arnings: ', ' $rr,rrr.rr ');
  644.       InsertField (Dialog, 0,0, FALSE, '', 'r'^H#0'r'^H#0'r'^H)^.Hide;
  645.       R.Assign (0, 8, 10, 10);
  646.       B := New (PButton, Init (R, 'O~K~', cmOK, bfDefault));
  647.       B^.Options := B^.Options or ofCenterX;
  648.       Insert (B);
  649.       SelectNext (FALSE);
  650.       SetData (Payroll [P^.CurrentRecord]);
  651.       end;
  652.     TrimDialog (Dialog);
  653.     Control := DeskTop^.ExecView (Dialog);
  654.     If (Control = cmOK) then
  655.       begin
  656.       { return record to table }
  657.       Dialog^.GetData (Payroll [P^.CurrentRecord]);
  658.       P^.RecalcRecord;
  659.       { redraw all windows that use Payroll }
  660.       Message (DeskTop, evBroadcast, cmDMX_DrawData, @Payroll);
  661.       end;
  662.     Dispose (Dialog, Done);
  663.     end;
  664. end;
  665.  
  666.  
  667. procedure TMyApp.BusyDialog (P : PDmxEditTbl);
  668. var  R       : TRect;
  669.      Dialog  : PCursorDlg;
  670.      B       : PButton;
  671.      A       : string;
  672.      Control : word;
  673. begin
  674.   Str (succ (P^.CurrentRecord), A);
  675.   DeskTop^.GetExtent (R);
  676.   Dialog := New (PCursorDlg, Init (R, 'Busy Record #' + A));
  677.   If (Dialog <> nil) then
  678.     begin
  679.     With Dialog^ do
  680.       begin
  681.       HelpCtx  := hcDialogs;
  682.  
  683.       { The Read-Only and Hidden fields are also inserted into this view
  684.     so that the entire BusyInfo record structure is transferable.
  685.     They can be hidden using TView^.Hide() because InsertField() is
  686.     a function that returns a PView pointer --as demonstrated in the
  687.     following instance...
  688.        }
  689.       InsertField (Dialog, 0,  0, FALSE, '',  'B')^.Hide;
  690.       InsertField (Dialog, 2,  2, FALSE, '~N~ame:    ',  ' ssssssssssssssssssssss');
  691.       InsertField (Dialog, 2,  4, FALSE, '~S~SN:     ',  ' ###-##-#### ');
  692.       InsertField (Dialog, 2,  6, FALSE, '~B~alance: ',  '($rrr,rrr.rr)');
  693.       InsertField (Dialog,11,  8, TRUE,  '  ~D~ate         Time', fldDATETIME);
  694.       InsertField (Dialog, 0,  0, FALSE, '',  'i')^.Hide;
  695.       InsertField (Dialog, 2, 11, FALSE, '~I~nteger: ',  'iii');
  696.       InsertField (Dialog, 2, 13, FALSE, '~P~ointer: ',  ' HHHH:HHHH ');
  697.       InsertField (Dialog, 2, 14, FALSE, '~V~alue:   ',  'RRR,RRR.RRR ~pts~ ');
  698.       InsertField (Dialog, 0,  0, FALSE, '',  'B')^.Hide;
  699.  
  700.       R.Assign (0, 16, 10, 18);
  701.       B := New (PButton, Init (R, 'O~K~', cmOK, bfDefault));
  702.       B^.Options := B^.Options or ofCenterX;
  703.       Insert (B);
  704.       SelectNext (FALSE);
  705.       SetData (BusyData [P^.CurrentRecord]);
  706.       end;
  707.  
  708.     TrimDialog (Dialog);
  709.     Control := DeskTop^.ExecView (Dialog);
  710.     If (Control = cmOK) then
  711.       begin
  712.       { return record to table }
  713.       Dialog^.GetData (BusyData [P^.CurrentRecord]);
  714.       { redraw all windows that use BusyData }
  715.       Message (DeskTop, evBroadcast, cmDMX_DrawData, @BusyData);
  716.       end;
  717.     Dispose (Dialog, Done);
  718.     end;
  719. end;
  720.  
  721.  
  722.   { ══════════════════════════════════════════════════════════════════════ }
  723.  
  724.  
  725. procedure InitializeData;
  726. { creates test data }
  727. var  i,j  : integer;
  728. begin
  729.   fillchar (Accounts,  sizeof (Accounts),  0);
  730.   fillchar (Payroll,   sizeof (Payroll),   0);
  731.   fillchar (BusyData,  sizeof (BusyData),  0);
  732.  
  733.   BusyData [00].Name := 'Abigail Adams';
  734.   BusyData [01].Name := 'Betty Boop';
  735.   BusyData [02].Name := 'Clark Clifford';
  736.   BusyData [03].Name := 'Dana Delaney';
  737.   BusyData [04].Name := 'Elbert Eagleton';
  738.   BusyData [05].Name := 'Farrah Fawcett';
  739.   BusyData [06].Name := 'Ginger Grant';
  740.   BusyData [07].Name := 'Hugh Hefner';
  741.   BusyData [08].Name := 'Inga Ingersol';
  742.   BusyData [09].Name := 'John Jay';
  743.   BusyData [10].Name := 'Katie Kingfield';
  744.   BusyData [11].Name := 'Lois Lane';
  745.   BusyData [12].Name := 'Melissa Manchester';
  746.   BusyData [13].Name := 'Nancy Nichols';
  747.   BusyData [14].Name := 'Oscar O''Malley';
  748.   BusyData [15].Name := 'Paula Prentiss';
  749.   BusyData [16].Name := 'Quincy Quenton';
  750.   BusyData [17].Name := 'Rita Rudner';
  751.   BusyData [18].Name := 'Samantha Stevens';
  752.   BusyData [19].Name := 'Tina Turner';
  753.   BusyData [20].Name := 'Ute Ueberroth';
  754.   BusyData [21].Name := 'Vicky Vail';
  755.   BusyData [22].Name := 'Wendy Wilson';
  756.   BusyData [23].Name := 'Xavier X. Xylvert';
  757.   BusyData [24].Name := 'Yamaha Yesta';
  758.   BusyData [25].Name := 'Zorro';
  759.  
  760.   For i := 0 to MaxRecordNum do
  761.     begin
  762.     BusyData [i].intfield0  := i;
  763.     BusyData [i].hextwo     := lo (i);
  764.     If i < 26 then
  765.       begin
  766.       BusyData [i].intfield1    := Mem [0:i];
  767.       BusyData [i].ptrfield    := pointer (MemL [0:i shl 2]);
  768.       BusyData [i].realfield1    := random (200) * random (200) / succ (random (199));
  769.       BusyData [i].realfield2    := random (200) * random (200) / succ (random (199));
  770.  
  771.       BusyData [i].DT.Year    := 1988 + random (4);
  772.       BusyData [i].DT.Month    := succ (random (12));
  773.       BusyData [i].DT.Day    := succ (random (28));
  774.  
  775.       BusyData [i].DT.Hour    := random (24);
  776.       BusyData [i].DT.Min    := random (60);
  777.       BusyData [i].DT.Sec    := random (60);
  778.  
  779.       BusyData [i].SSN [0]    := #9;
  780.       For j := 1 to 9 do BusyData [i].SSN [j] := chr (random (10) + 48);
  781.       end;
  782.     end;
  783.  
  784.   BusyData [0].SSN  := '';
  785.  
  786.   Accounts [0].Account := 'ACME TOOL CO.';
  787.   Accounts [1].Account := 'READING R. R.';
  788.   Accounts [2].Account := 'EXXON CORP.';
  789.   For i := 0 to 2 do With Accounts [i] do
  790.     begin
  791.     Debit   := Random (50000) * 0.9;
  792.     Credit  := Random (50000) * 0.9;
  793.     Status  := (Credit > Debit);
  794.     end;
  795.  
  796.   Payroll [0].Employee := 'Alex Trebek';
  797.   Payroll [1].Employee := 'Pat Sajak';
  798.   Payroll [2].Employee := 'Vanna White';
  799.   Payroll [3].Employee := 'Merv Griffin';
  800.   For i := 0 to 3 do With Payroll [i] do
  801.     begin
  802.     ID        :=  Random (400);
  803.     Earnings    :=  Random (3000) + 4000.0;
  804.     FICA    :=  Earnings * 0.075;
  805.     FITW    :=  Earnings * 0.28;
  806.     SITW    :=  Earnings * 0.05;
  807.     end;
  808. end;
  809.  
  810.  
  811.   { ══════════════════════════════════════════════════════════════════════ }
  812.  
  813. var  MyApp  : TMyApp;
  814.  
  815. Begin
  816.   MyApp.Init;
  817.   MyApp.Run;
  818.   MyApp.Done;
  819. End.
  820.